package com.origin.onlinesys.web.controllers.modules.interviewsys;

import com.origin.onlinesys.common.controllers.BaseController;
import com.origin.onlinesys.domain.modules.interviewsys.InterviewerTrace;
import com.origin.onlinesys.service.modules.interviewsys.impl.InterviewerTraceServiceImpl;
import com.origin.onlinesys.web.utils.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2015/1/25 0025.
 * 面试追踪
 */
@Controller
@RequestMapping(value = "/management/interviewerTrace")
public class InterviewerTraceController extends BaseController{
    @Autowired
    private InterviewerTraceServiceImpl service;

    @RequestMapping(value = "/findAll")
    public @ResponseBody
    List<InterviewerTrace> findAll(){
        return service.selectAll();
    }

    @RequestMapping(value = "/findByWhere")
    public @ResponseBody
    List<InterviewerTrace> findByWhere(@ModelAttribute InterviewerTrace trace){
        return service.selectByWhere(trace);
    }

    @RequestMapping(value = "/findByIntervId")
    public @ResponseBody
    List<InterviewerTrace> findByIntervId(String id){
        return service.selectByIntervId(id);
    }

    @RequestMapping(value = "/add")
    public @ResponseBody int  addTrace(@ModelAttribute InterviewerTrace trace,String userName){
        if(WebUtils.getAccount().getRealname().equals(userName)){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            trace.setVisitTime(sdf.format(new Date()));
            trace.setUserId(WebUtils.getUserId());
            service.insertTrace(trace);
        }
        return 1;
    }

    @RequestMapping(value = "/update")
    public void updateTrace(@ModelAttribute InterviewerTrace trace){
        service.updateTrace(trace);
    }

    @RequestMapping(value = "/del")
    public @ResponseBody
    String delete(String id){
        service.deleteTrace(id);
        return "1";
    }
}
